package net.hn.hnms.biz.mine.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.hn.hnms.biz.mine.domain.dto.CoverageDto;
import net.hn.hnms.biz.mine.domain.dto.DefinedSensorDto;
import net.hn.hnms.biz.mine.domain.vo.CoverageListVo;
import net.hn.hnms.biz.mine.domain.vo.CoverageTreeListVo;
import net.hn.hnms.biz.mine.service.CoverageService;
import net.hn.hnms.biz.mine.vo.*;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import net.hn.hnms.biz.mine.vo.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 图层系统标注坐标功能
 */
@RestController
@RequestMapping("coverage")
@Api(value = "图层系统标注控制器", tags = {"图层系统标注控制器"})
public class CoverageController {

    @Resource
    private CoverageService coverageService;


    @ApiOperation("根据系统类型获取测点列表")
    @GetMapping("getBaseListByType")
    @AutoSetMineCode
    public R<List<BaseSensorVo>> getBaseListByType(@ApiParam(value = "根据字典“biz_mineInfo_coverageOS_type“"+"获取相应的系统测点列表",required = true) String osType,
                                                   @ApiParam(value = "煤矿编码")  String mineCode,
                                                   @ApiParam(value = "煤矿编码")  String companyCode) {
        List<BaseSensorVo> baseSensorVos=coverageService.getBaseListByType(osType,mineCode,companyCode);
        if (baseSensorVos.isEmpty()) {
            return R.ok(new ArrayList<>());
        }
//
        return R.ok(baseSensorVos);
    }

    @ApiOperation("自定义测点-新增测点")
    @PostMapping("customAdd")
    public R customAdd(@RequestBody DefinedSensorDto definedSensorDto) {
        Boolean is =coverageService.customAdd(definedSensorDto);
        if (is) {
            return R.ok();
        }
        return R.fail();
    }

    @ApiOperation("根据图层Code获取系统列表")
    @GetMapping("getSystemListByCoverageCode")
    @AutoSetMineCode
    public R getSystemListByCoverageCode(String coverageCode,@ApiParam(value = "煤矿编码")  String mineCode) {
//        Boolean is =coverageService.customAdd(definedSensorDto);
//        if (is) {
//            return R.ok();
//        }
        return R.fail();
    }
    @ApiOperation("获取图层树状列表")
    @GetMapping("getCoverageTreeList")
    @AutoSetMineCode
    public R<List<CoverageTreeListVo>> getCoverageTreeList(@ApiParam(value = "煤矿编码")String mineCode) {
        List<CoverageTreeListVo> coverageTreeList =coverageService.getCoverageTreeList(mineCode);
        return R.ok(coverageTreeList);

    }

    @ApiOperation("更新测点坐标")
    @PutMapping("UpDataSensorCoordinate")
    @AutoSetMineCode
    public R UpDataSensorCoordinate(@RequestBody BaseSensorDto baseSensorDto) {
        Boolean is=coverageService.UpDataSensorCoordinate(baseSensorDto);
        if (is) {
            return R.ok("更新成功");
        }
        return R.fail("更新失败");
    }
    @ApiOperation("批量删除测点坐标")
    @DeleteMapping ("deleteSensorCoordinate")
    @AutoSetMineCode
    public R deleteSensorCoordinate(@RequestBody SensorCoordinateDto sensorCoordinateDto) {
        Boolean is=coverageService.deleteSensorCoordinate(sensorCoordinateDto);
        if (is) {
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }
    @ApiOperation("更新图层测点列表")
    @PutMapping("UpDataCoverageSensorList")
    @AutoSetMineCode
    public R UpDataCoverageSensorList(@RequestBody CoverageSensorListDto coverageSensorListDto) {
        Boolean is=coverageService.UpDataCoverageSensorList(coverageSensorListDto);
        if (is) {
            return R.ok("更新成功");
        }
        return R.fail("更新失败");
    }
    @ApiOperation("根据图层编码获取系统测点列表")
    @GetMapping("getOsListByType")
    @AutoSetMineCode
    public R<List<CoverageSystemListDto>> getOsListByType(@ApiParam(value = "根据字典图层编码获取相应的图层测点列表",required = true) String coverageType,
                                                          @ApiParam(value = "煤矿编码")  String mineCode,
                                                          @ApiParam(value = "煤矿编码")  String companyCode) {
        List<CoverageSystemListDto> coverageSystemListDtos =coverageService.getOsListByType(coverageType,mineCode,companyCode);
        if (!coverageSystemListDtos.isEmpty()) {
            return R.ok(coverageSystemListDtos);
        }
        return R.fail(new ArrayList<>());
    }
    @ApiOperation("图层-获取图层信息列表")
    @GetMapping("getCoverageList")
    @AutoSetMineCode
    public R<List<CoverageListVo>> getCoverageList(@ApiParam(value = "煤矿编码")  String mineCode) {
        List<CoverageListVo> coverageListVos =coverageService.getCoverageList(mineCode);
        if (!coverageListVos.isEmpty()) {
            return R.ok(coverageListVos);
        }
        return R.fail(new ArrayList<>());
    }
    @ApiOperation("图层-新增图层")
    @PostMapping("coverageAdd")
    public R coverageAdd(@RequestBody CoverageDto coverageDto) {
        Boolean is =coverageService.coverageAdd(coverageDto);
        if (is) {
            return R.ok();
        }
        return R.fail();
    }
    @ApiOperation("图层-加锁或解锁")
    @PostMapping("coverageLockFlag")
    public R coverageLockFlag(@ApiParam(value = "图层编码")  String coverageCode,@ApiParam(value = "煤矿编码")  String mineCode) {
        Boolean is = coverageService.coverageLockFlag(coverageCode, mineCode);
        if (is) {
            return R.ok();
        }
        return R.fail();
    }
    @ApiOperation("图层-批量删除图层")
    @DeleteMapping ("coverageDelete")
    public R coverageDelete(@RequestBody @ApiParam(value = "图层编码")  List<String> coverageCodeList) {
        Boolean is = coverageService.coverageDelete(coverageCodeList);
        if (is) {
            return R.ok();
        }
        return R.fail();
    }

}
